﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using HP.Cachalote.DataModels;
using HP.Cachalote.Services.Validations;

namespace HP.Cachalote.WPF.ValidationRules
{
    public class TodoItemTitleValidationRule : ValidationRule
    {
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            var todoItemValidator = new TodoItemValidator();

            var item = new TodoItem
            {
                Title = value.ToString().Trim()
            };

            if (!todoItemValidator.CheckTitleLength(item))
            {
                return new ValidationResult(false, todoItemValidator.GetError(TodoItemValidator.TitleErrorKey));
            }

            return new ValidationResult(true, null);
        }
    }
}
